<template>
  <div class="fee-config">
    <!-- 搜索栏 -->
    <div class="search-block">
      <div class="item-msg" v-if="$store.state.userInfo.group === 'administrator'">
        <label>钱包</label>
        <el-select v-model="searchForm.platform_id" placeholder="全部" size="mini" @change="search()">
          <el-option v-for="item in wallets" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </div>
      <div class="item-msg">
        <label>转账类型</label>
        <el-select
          v-model="searchForm.transfer_type"
          placeholder="全部"
          size="mini"
          @change="search()"
        >
          <el-option label="外部" :value="1"></el-option>
          <el-option label="内部" :value="2"></el-option>
        </el-select>
      </div>
    </div>
    <!-- 数据表 -->
    <div class="data-table">
      <el-table
        size="small"
        v-loading="loading"
        element-loading-text="拼命加载中..."
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(211, 215, 212, 0.5)"
        :data="tableData"
        stripe
        header-cell-class-name="headerStyle"
        style="width: 100%"
      >
        <el-table-column align="center" prop="id" label="id" width="120"></el-table-column>
        <el-table-column align="center" prop="coin.name" label="币种名称" width="120"></el-table-column>
        <el-table-column align="center" prop="icon" label="收取类型">
          <template slot-scope="item">{{item.row.fees_type===1?'固定手续费':'百分比手续费'}}</template>
        </el-table-column>
        <el-table-column align="center" prop="fees" label="最低手续费"></el-table-column>
        <el-table-column align="center" label="手续费" prop="transaction_fees">
          <template
            slot-scope="item"
          >{{item.row.fees_type===1?item.row.transaction_fees:`${parseFloat((item.row.transaction_fees*100).toFixed(2))}%`}}</template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="180">
          <template slot-scope="item">
            <el-button type="text" @click="edit(item.row)" class="edit-btn">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <pages
        :pages="searchForm"
        :total="total"
        @pageSizeChange="pageSizeChange"
        @pageChange="pageChange"
      ></pages>
      <!-- 添加配置弹窗 -->
      <transition name="fade">
        <fee-set
          v-if="showDialog"
          @cancel="showDialog=false"
          @success="showDialog=false;search()"
          :operateData="operateData"
        ></fee-set>
      </transition>
    </div>
  </div>
</template>

<script>
import Pages from "@/components/PageBox.vue";
import FeeSet from "@/components/CoinsManage/FeeSet.vue";
import { feesList } from "./Coins.service.js";
export default {
  components: {
    Pages,
    FeeSet
  },
  computed: {
    wallets() {
      return this.$store.state.wallet_list || [];
    }
  },
  data() {
    return {
      loading: false,
      searchForm: {
        platform_id: String(this.$store.state.userInfo.platform_id),
        page: 1,
        size: 10,
        transfer_type: 1 //1-外部，2-内部
      },
      tableData: [],
      total: 10,
      operateData: {},
      showDialog: false
    };
  },

  mounted() {
    this.search();
  },
  methods: {
    async search() {
      const res = await feesList(this.searchForm);
      this.tableData = res.data.items || [];
      this.total = res.data.total || 0;
    },
    edit(data) {
      this.operateData = data || {};
      this.showDialog = true;
    },
    pageChange(val) {
      this.searchForm.page = val;
      this.search();
    },
    pageSizeChange(val) {
      this.searchForm.size = val;
      this.searchForm.page = 1;
      this.search();
    }
  }
};
</script>

<style lang="scss" scoped>
.fee-config {
  min-height: calc(100vh - 100px);
  .search-block {
    width: 100%;
    padding: 20px 30px 10px;
    .item-msg {
      display: inline-block;
      margin-right: 35px;
      font-size: 1 size= "medium" 4;
      color: $admin_font_param;
      label {
        display: inline-block;
        max-width: 90px;
        text-align: right;
        margin-right: 10px;
      }
      .el-input {
        width: 150px;
      }
      .el-select {
        width: 150px;
      }
    }
    .search-btn {
      margin-left: 25px;
    }
  }
  .data-table {
    padding-bottom: 20px;
    background: #fff;
    border-radius: 5px;
    margin-top: 30px;
    box-shadow: rgba(0, 0, 0, 0.1) 0 0 15px;
    .edit-btn {
      color: #2f86f2;
    }
  }
  .fade-enter-active,
  .fade-leave-active {
    transition: opacity 0.3s;
  }
  .fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
    opacity: 0;
  }
}
</style>